﻿using System;
using System.Data;
using System.Data.SqlClient;

public class ChangePasswordDAL
{
    dbConnection db = new dbConnection();

    public  int ChangePassword(ChangePasswordBO ChangePassword)
    {
        SqlConnection cn = null;
        SqlCommand cmd = null;
        int Counter = 0;

        try
        {
            cn = new SqlConnection();
            cn.ConnectionString = db.GetCS();

            cmd = new SqlCommand();
            cmd.Connection = cn;
            cmd.CommandType = CommandType.Text;
            cmd.CommandText = "UPDATE [Registrations] SET  [Password]=@Password WHERE UserName=@UserName";
            
            cmd.Parameters.AddWithValue("@UserName", ChangePassword.UserName);
            cmd.Parameters.AddWithValue("@Password", ChangePassword.Password);

            cn.Open();
            Counter = cmd.ExecuteNonQuery();

        }
        catch (Exception ex)
        {
            throw new Exception(ex.Message);
        }
        finally
        {
            if (cn != null)
            {
                cn.Close();
                cn.Dispose();
                cn = null;
            }
        }
        return (Counter);
    }

}

